package com.xtzn.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xtzn.business.IUserBusiness;
import com.xtzn.enums.ResponseEnum;
import com.xtzn.click.vo.CSResponse;
import com.xtzn.mapper.entity.User;

/**
 * 功能描述: <br>
 * **
 * 
 * @author zyw
 * @version [版本号, 2018年4月17日]
 */
@Controller
@RequestMapping("/userManage")
public class UserManageController {

	@Autowired
	private IUserBusiness userBusiness;
	/*
	@Autowired
	private IAuthorityBusiness authorityBusiness;*/
	
	@RequestMapping(value="/login",method={RequestMethod.POST})
	@ResponseBody
	public CSResponse login(User user){
		if(user.getUserName()==null||user.getPassword()==null){
			return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());
		}
		return userBusiness.login(user);
	}
	@RequestMapping(value="/retrieveUserByPage",method={RequestMethod.POST})
	@ResponseBody
	public CSResponse retrieveUserByPage(Integer pageIndex){
		if(pageIndex==null){
			return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());
		}
		return userBusiness.retrieveUserByPage(pageIndex);
	}
	@RequestMapping(value="/createUser",method={RequestMethod.POST})
	@ResponseBody
	public CSResponse createUser(User user){
		if(user.getUserName()==null||user.getPassword()==null||user.getFranchiseeName()==null){
			return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());
		}
		return userBusiness.createUser(user);
	}
	@RequestMapping(value="/modifyUser",method={RequestMethod.POST})
	@ResponseBody
	public CSResponse modifyUser(User user){
		if(user.getId()!=null){
			return userBusiness.modifyUser(user);
		}
		return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());
	}
	
	/*@RequestMapping(value="/modifyAuthority",method={RequestMethod.POST})
	@ResponseBody
	public CSResponse modifyAuthority(Authority authority){
		if(authority.getId()!=null){
			return authorityBusiness.modifyAuthority(authority);
		}
		return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());
	}
	@RequestMapping(value="/createAuthority",method={RequestMethod.POST})
	@ResponseBody
	public CSResponse createAuthority(Authority authority){
		if(authority.getAccountInfo()==null||authority.getAccountType()==null||authority.getAlliance()==null){
			return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());	
		}
		if(authority.getAppleAccount()==null||authority.getCountry()==null||authority.getIdfa()==null){
			return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());	
		}
		if(authority.getIgg()==null||authority.getIosSystemVersion()==null||authority.getIphoneModel()==null){
			return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());	
		}
		if(authority.getIphoneProgram()==null||authority.getIphoneRule()==null||authority.getPersonInfo()==null){
			return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());	
		}
		if(authority.getPersonType()==null||authority.getRetained()==null||authority.getRetainedProgram()==null){
			return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());	
		}
		if(authority.getTask()==null||authority.getTimelineGrogram()==null){
			return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());	
		}
		return authorityBusiness.createAuthority(authority);
	}
	@RequestMapping(value="/retrieveAllAuthority",method={RequestMethod.POST})
	@ResponseBody
	public CSResponse retrieveAllAuthority(){
		
		return authorityBusiness.retrieveAllAuthority();
	}
	@RequestMapping(value="/retrieveAuthorityByPage",method={RequestMethod.POST})
	@ResponseBody
	public CSResponse retrieveAuthorityByPage(Integer pageIndex){
		if(pageIndex!=null){
			return authorityBusiness.retrieveAuthorityByPage(pageIndex);
		}
		return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());
	}
	@RequestMapping(value="/retrieveAuthorityById",method={RequestMethod.POST})
	@ResponseBody
	public CSResponse retrieveAuthorityById(Authority authority){
		Integer id = authority.getId();
		if(id!=null){
			return authorityBusiness.retrieveAuthorityById(id);
		}
		return new CSResponse(ResponseEnum.RECEIVE_ERROR.getCode(),ResponseEnum.RECEIVE_ERROR.getDesc());
	}*/
}
